import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

/**
 *
 * @author VIK
 */
public class Frequency {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine().trim());
        int k = 0;
        TreeMap<String, Integer> tm = new TreeMap<String, Integer>();
        for (int i = 0; i < n; i++) {
            String s = sc.nextLine();
            if (tm.containsKey(s)) {
                tm.put(s, tm.get(s) + 1);
            } else {
                tm.put(s, 1);

            }
        }
        k = Integer.parseInt(sc.nextLine().trim());
         
        ArrayList ls = new ArrayList(tm.entrySet());
        Collections.sort(ls, new Compare());
        Iterator iterator = ls.iterator();
        while (iterator.hasNext() && k > 0) {

            Map.Entry e = (Map.Entry) iterator.next();
            if (k != 1) {
                System.out.println(e.getKey());
            } else {
                System.out.print(e.getKey());
            }
            k--;
        }
        
    }

    static class Compare implements Comparator {

        @Override
        public int compare(Object o1, Object o2) {
            int result = 0;
            Map.Entry e1 = (Map.Entry) o1;
            Map.Entry e2 = (Map.Entry) o2;
            int val1 = (Integer) e1.getValue();
            int val2 = (Integer) e2.getValue();
            if(val1==val2)
                return ((String)e1.getKey()).compareToIgnoreCase((String)e2.getKey());
            return val2 - val1;

        }
    }
}